/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package expo43playlist;

import java.io.*;
import java.net.*;

/**
 *
 * @author TommySprat
 */
public class ClientThread extends Thread {

    Socket e43Socket = null;
    PrintWriter out = null;
    BufferedReader in = null;
    String HOST = "localhost";
    Expo43PlaylistView myPlaylistView;

    public ClientThread(Expo43PlaylistView masterScoreView) {
        myPlaylistView = masterScoreView;
    }

    @Override
    public void run() {
        try {
            e43Socket = new Socket(HOST, 4446);
            out = new PrintWriter(e43Socket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(e43Socket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: " + HOST);
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: " + HOST);
            System.exit(1);
        }

        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String fromServer;
        String toServer;

        try {
            while ((fromServer = in.readLine()) != null) {
                if (fromServer.equalsIgnoreCase("startplaylist")) {
                    myPlaylistView.setVisible(true);
                }
                if (fromServer.equalsIgnoreCase("stopplaylist")) {
                    myPlaylistView.setVisible(false);
                }
                if (fromServer.equalsIgnoreCase("Scene1-Intro.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(0);
                }
                if (fromServer.equalsIgnoreCase("Scene2-Intro.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(1);
                }
                if (fromServer.equalsIgnoreCase("Scene3-SE.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(2);
                }
                if (fromServer.equalsIgnoreCase("Scene4-GD.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(3);
                }
                if (fromServer.equalsIgnoreCase("Scene5-HCD.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(4);
                }
                if (fromServer.equalsIgnoreCase("Scene6-ITM.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(5);
                }
                if (fromServer.equalsIgnoreCase("Scene7-SNE.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(6);
                }
                if (fromServer.equalsIgnoreCase("Scene8-TC.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(7);
                }
                if (fromServer.equalsIgnoreCase("Scene9-ITGame.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(8);
                }
                if (fromServer.equalsIgnoreCase("Scene10-Outtro.wmv")) {
                    myPlaylistView.setNowPlayingSceneIndex(9);
                }
                if (fromServer.equalsIgnoreCase("Bye.")) {
                    break;
                }

            }
        } catch (IOException exc) {
            System.out.println("DERP IOException");
            exc.printStackTrace();
        }
    }
}
